<%@ include file="shared_header.jsp" %>
<%@ page import="vrp.Partner" %>

<%
	SimpleDateFormat sdf = new SimpleDateFormat ("yyyy-MM-dd");
	PersistenceManager pm = PMF.get().getPersistenceManager();
	String query = "";
	
	String[] whProviderStatusValue = {Integer.toString(0),Integer.toString(1)};
	String[] whProviderStatusDisplay = {"Servicing","Suspended"};
%>

	<div style="padding: 0px 10px;">
		<h2>List of WHProviders</h2>
		<table style="width: 100%;">
<%
	query = "select from " + Partner.class.getName() + " where type == 2 order by name asc";
    List<Partner> whProviders = (List<Partner>) pm.newQuery(query).execute();
    if (whProviders.isEmpty()) {
%>
			<tr><td>There is no warehouse provider in the database.</td></tr>
<%
    } else {
%>
			<tr>
				<th>Name</th>
				<th>Address</th>
				<th>Postal Code</th>
				<th>Contact No</th>
				<th>Status</th>
				<th>Action</th>
			</tr>
<%
        for (Partner p : whProviders) {
%>
			<tr>
				<td style="text-align: left;"><%= p.getName() %></td>
				<td style="text-align: left;"><%= p.getAddress() %></td>
				<td style="text-align: center;"><%= p.getPostalCode() %></td>
				<td style="text-align: center;"><%= p.getContactNo() %></td>
				<td style="text-align: center;"><%= writeSwitch(Integer.toString(p.getStatus()),whProviderStatusValue,whProviderStatusDisplay) %></td>
				<td style="text-align:center;">
					<input type="button" value="Edit" class="buttonedit"/>
					<input type="button" value="Delete" class="buttondelete"/>
				</td>
			</tr>
			<tr style="display: none;">
				<td colspan="6">
					<form action="/editpartner" method="post">
						<div><b>Edit Warehouse Provider</b></div>
			    		<div>Name:&nbsp;<input type="text" name="name" value="<%= p.getName() %>" /></div>
			    		<div>Address:&nbsp;<input type="text" name="address" value="<%= p.getAddress() %>" /></div>
			    		<div>Postal Code:&nbsp;<input type="text" name="postalCode" value="<%= p.getPostalCode() %>" /></div>
			    		<div>Contact No:&nbsp;<input type="text" name="contactNo" value="<%= p.getContactNo() %>" /></div>
			    		<div>Status:&nbsp;<%= writeSelect("status",Integer.toString(p.getStatus()),whProviderStatusValue,whProviderStatusDisplay) %></div>
			    		<input type="hidden" name="key" value="<%= p.getKey().getId() %>"/>
						<input type="submit" value="Edit" />
						<input type="button" value="Cancel" class="buttoncancel" />
					</form>
				</td>
			</tr>
			<tr style="display: none;">
				<td colspan="6">
					<form action="/deletepartner" method="post">
						<div><b>Delete WHProvider</b></div>
			    		<div>This action would delete the above warehouse provider permanently. Proceed?</div>
						<input type="hidden" name="key" value="<%= p.getKey().getId() %>"/>
						<input type="submit" value="Delete" />
						<input type="button" value="Cancel" class="buttoncancel" />
					</form>
				</td>
			</tr>
<%
        }
    }
%>
			
		</table>
		<input type="button" value="Add WHProvider" class="buttonadd" />
  		<div style="display: none;">
			<form action="/addpartner" method="post">
	    		<div>Name:&nbsp;<input type="text" name="name" /></div>
	    		<div>Address:&nbsp;<input type="text" name="address" value="" /></div>
	    		<div>Postal Code:&nbsp;<input type="text" name="postalCode" value="" /></div>
	    		<div>Contact No:&nbsp;<input type="text" name="contactNo" value="" /></div>
	    		<input type="hidden" name="type" value="2"/>
	    		<div><input type="submit" value="Add" /><input type="button" value="Cancel" class="buttoncancel" /></div>
	  		</form>
	  	</div>
	</div>
	
<%
    pm.close();
%>

<%@ include file="shared_footer.jsp" %>